home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 …ember: Reference Library / Dev.CD Dec 94.toast / What's New? / Sample Code / Snippets Update / Movie SetTrackGWorld ƒ / mtb3.c < prev    next >
Encoding:
Text File  |  1994-10-21  |  4.9 KB  |  206 lines  |  [TEXT/KAHL]

  1. // This is based on the sample code on the QuickTime 1.5 CD ROM
  2. //
  3. // Display a movie in a window using a movie controller
  4. // The window is larger than the movie, if the user clicks
  5. // in the content area of the window, hide the controller
  6. // and stop the movie playing, which will show the badge.
  7. //
  8. //    Copyright:    © 1992-4 by Apple Computer, Inc., all rights reserved.
  9. // 
  10.  
  11. #include "mtb.h"
  12.  
  13. void    CreateMovieWindow( Movie aMovie ) ;
  14. void    DestroyMovieWindow( WindowPtr aWindow ) ;
  15. void     MainEventLoop( void ) ;
  16. void     InitMac( void ) ;
  17.  
  18.  
  19. void    CreateMovieWindow( Movie aMovie ) 
  20. {
  21.     Rect                         aRect;
  22.     MovieController                aController;
  23.     WindowPtr                     aWindow;
  24.     RGBColor                    nattyGray = { 45000, 45000, 45000 } ;
  25.     
  26.     // prototype::
  27.     GWorldPtr    SetTransferProcsForMovie( Movie aMovie ) ;
  28.  
  29.     if( aMovie == nil )
  30.         CheckError( paramErr, "\pCreateMovieWindow was passed nil for aMovie") ;
  31.         
  32.     // Use the movie bounding rect to size the movie
  33.     GetMovieBox( aMovie, &aRect );
  34.     
  35.     // create a window for the movie
  36.     aWindow = NewCWindow(    nil, 
  37.                             &aRect, 
  38.                             "\pMovie", 
  39.                             false, 
  40.                             noGrowDocProc, 
  41.                             (WindowPtr)-1, 
  42.                             true, 
  43.                             0 );
  44.                             
  45.     // set our port to the newly created movie window
  46.     SetPort (aWindow);
  47.     
  48.     // set the movies environment to the current
  49.     // port and gDevice (pass nil for defaults)
  50.     SetMovieGWorld( aMovie, nil, nil ) ;
  51.     
  52.     // set up an offscreen bitmap and transfer proc for the movie
  53.     // GWorldPtr    SetTransferProcsForMovie( Movie aMovie ) ;
  54.     
  55.     SetTransferProcsForMovie( aMovie ) ;
  56.         
  57.     // create a movie controller for the movie
  58.     aController = NewMovieController (aMovie, &aRect, mcTopLeftMovie);
  59.     
  60.     // should have some error handling here
  61.     if (aController == nil) 
  62.         ExitToShell();
  63.  
  64.     // get the bounding rect of the movie plus the controller
  65.     CheckError( MCGetControllerBoundsRect(aController, &aRect), "\pMCGetControllerBoundsRect") ;
  66.     
  67.     SizeWindow (aWindow, aRect.right,
  68.                      aRect.bottom - 1, true);
  69.         
  70.     // move it to {50,50} on the main device and show it             
  71.     MoveWindow ( aWindow, 50, 50, true );                 
  72.     ShowWindow ( aWindow );
  73.     
  74.     // store a reference to the movie controller for this window 
  75.     // in the refcon field of this window, 1 movie per window...
  76.     SetWRefCon ( aWindow, (long)aController );
  77.  
  78. }
  79.  
  80. void    DestroyMovieWindow( WindowPtr aWindow )
  81. {
  82.     Movie                aMovie ;
  83.     MovieController        aController ;
  84.         
  85.     aController = (MovieController)GetWRefCon( aWindow ) ;
  86.     if( aController != nil ) {
  87.         aMovie = MCGetMovie( aController ) ;
  88.         if( aMovie != nil ) {
  89.             DisposeMovie (aMovie);
  90.         }
  91.         DisposeMovieController (aController);
  92.     }
  93.     
  94.     DisposeWindow(aWindow);
  95. }
  96.  
  97. void MainEventLoop( void ) 
  98. {
  99.     Boolean                     done = false;
  100.     OSErr                         err;
  101.     EventRecord                 theEvent;
  102.     WindowPtr                     whichWindow;
  103.     short                         part;
  104.     Boolean                        wasMovieEvent ;
  105.     MovieController                aController ;
  106.     
  107.     // use this in calls to MCDoAction
  108.     long                        myMCActionParams ;
  109.  
  110.     while (!done) {
  111.     
  112.         WaitNextEvent(everyEvent, &theEvent, 0, nil );
  113.         
  114.         // get the movie associated with the pront window
  115.         aController = (MovieController)( GetWRefCon(FrontWindow()) );
  116.         
  117.         // check we have a valid controller, and 
  118.         // if so, see if the controller can handle
  119.         // this event
  120.         
  121.         if( aController != nil )
  122.             wasMovieEvent = MCIsPlayerEvent(aController, &theEvent) ;
  123.         else
  124.             wasMovieEvent = false ;
  125.         
  126.         // if the controller didn't or couldn't handle it
  127.         // we need to handle it in the main event loop.
  128.             
  129.         if (!wasMovieEvent) {
  130.         
  131.             switch (theEvent.what) {
  132.             
  133.                 case updateEvt:    
  134.                     whichWindow = (WindowPtr)theEvent.message;
  135.                     BeginUpdate (whichWindow);
  136.                     EraseRect (&whichWindow->portRect);
  137.                     EndUpdate (whichWindow);
  138.                     break;
  139.                     
  140.                 case mouseDown:    
  141.                     part = FindWindow (theEvent.where,
  142.                                                 &whichWindow);
  143.                     // we only have one window, handle the event
  144.                     switch (part) {
  145.                         case inGoAway:    
  146.                             done = TrackGoAway (whichWindow,
  147.                                                 theEvent.where);
  148.                             
  149.                             // if the window got closed, dispose of our movie 
  150.                             // and the controller and the window.
  151.                             
  152.                             if( done )
  153.                                 DestroyMovieWindow( whichWindow ) ;
  154.                                 
  155.                             break;
  156.                             
  157.                         case inDrag:    
  158.                             DragWindow (whichWindow,
  159.                                              theEvent.where,
  160.                                              &qd.screenBits.bounds);
  161.                             break;
  162.                             
  163.                         case inContent:
  164.                             break ;
  165.                     }
  166.             }
  167.         }
  168.     }
  169. }
  170.  
  171. void InitMac( void )
  172. {
  173.     InitGraf (&qd.thePort);
  174.     InitFonts ();
  175.     InitWindows ();
  176.     InitMenus ();
  177.     TEInit ();
  178.     InitDialogs ((long)nil);
  179.     
  180.     MaxApplZone() ;
  181.     MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ; 
  182.     MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ; 
  183.     MoreMasters() ; MoreMasters() ; MoreMasters() ; MoreMasters() ; 
  184.     
  185.     if (!IsQuickTimeInstalled()) {
  186.         CheckError(-1,"\pPlease install QuickTime and try again.");
  187.     }
  188.     
  189.     CheckError( EnterMovies (), "\pEnterMovies failed" );    
  190. }
  191.  
  192.  
  193.  
  194. void main (void)
  195. {
  196.  
  197.     Movie        aMovie ;
  198.     
  199.     InitMac() ;
  200.  
  201.     if(aMovie = GetMovie ()) {
  202.         CreateMovieWindow( aMovie );
  203.         MainEventLoop() ;
  204.     }
  205. }
  206.